package com.cuit.blog.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cuit.blog.entity.Articletype;
import com.cuit.blog.entity.User;

import jakarta.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("")
public class IndexController {

	@GetMapping("")
	public ModelAndView findAll(Model model, HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("LoginUser");
		ModelAndView mav = new ModelAndView("login");
		if(user != null){
			mav = new ModelAndView("index");
			mav.addObject("username", user.getUsername());
			mav.addObject("mes", "Hello ");
			mav.addObject("gender", 5);
			mav.addObject("title", "网络空间安全学院");
			mav.addObject("content", "成都信息工程大学");
		}
		return mav;
	}

	@GetMapping("/login")
	public String login(Model model) {
		return "login";
	}

	@GetMapping("/logout")
	public String logout(HttpServletRequest request) {
		request.getSession().setAttribute("LoginUser", null);
		return "login";
	}
}
